package service

import (
	pb "demo_grpc/proto"
	"strconv"
)

type Stocks struct {
	pb.UnimplementedServiceStreamServerServer
}

func (st *Stocks) ListValue(req *pb.ServiceSimpleRequest, srv pb.ServiceStreamServer_ListValueServer) error {
	for n := 0; n < 5; n++ {
		// 向流中发送消息， 默认每次send送消息最大长度为`math.MaxInt32`bytes
		err := srv.Send(&pb.ServiceStreamResponse{
			StreamValue: req.Data + strconv.Itoa(n),
		})
		if err != nil {
			return err
		}
	}
	return nil
}
